<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      .container {
        width: 400px;
        height: 250px;
        border: 1px solid #000;
        margin: 50px auto;
        overflow: hidden;
      }
      ul {
        /* width: 1600px; */
        height: 250px;
        display: flex;
        /* transform: translateX(0px); */
        /* transition: all 0.4s; */
      }
      .hastst {
        transition: all 0.4s;
      }
      li {
        width: 400px;
        height: 250px;
        list-style: none;
      }
      img {
        width: 100%;
        height: 100%;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <div class="container" @mouseover="stop" @mouseout="restart">
        <ul
          :style="{transform:  'translateX(' + tst * -400 + 'px)', width: imgList.length * 400 + 'px'}"
          :class="{hastst: hastst}"
        >
          <li v-for="(item, index) in imgList" :key="index">
            <img :src="item" alt="" />
          </li>
        </ul>
      </div>
      <button>&lt;</button>
      <button @click="rightClick">&gt;</button>
    </div>

    <script src="../Vue.js"></script>
    <script>
      let timer;
      new Vue({
        el: "#app",
        data: {
          imgList: [
            "https://img.alicdn.com/imgextra/i3/6000000004151/O1CN01YIy87D1gXCpDNhbIF_!!6000000004151-0-octopus.jpg",
            "https://gtms03.alicdn.com/tps/i3/TB1gXd1JXXXXXapXpXXvKyzTVXX-520-280.jpg",
            "https://gtms02.alicdn.com/tps/i2/TB10vPXKpXXXXacXXXXvKyzTVXX-520-280.jpg",
            "https://img.alicdn.com/imgextra/i3/6000000004756/O1CN01v4QiAu1l0IRWp0biz_!!6000000004756-0-octopus.jpg",
            "https://img.alicdn.com/imgextra/i3/6000000004151/O1CN01YIy87D1gXCpDNhbIF_!!6000000004151-0-octopus.jpg",
          ],
          tst: 0,
          hastst: true,
        },
        methods: {
          rightClick() {
            this.tst++;
            this.hastst = true;
            if (this.tst === this.imgList.length - 1) {
              setTimeout(() => {
                this.hastst = false;
                this.tst = 0;
              }, 400);
            }
          },
          stop() {
            clearInterval(timer);
          },
          restart() {
            timer = setInterval(() => {
              this.rightClick();
            }, 4000);
          },
        },
        mounted() {
          timer = setInterval(() => {
            this.rightClick();
          }, 4000);
        },
      });
    </script>
  </body>
</html>
